package thebesttaskmanager.logical;

import java.util.Date;

import thebesttaskmanager.idmanager.IdManager;
import thebesttaskmanager.inputparser.Command;

public class Task {
	private boolean done = false;
	private String ID = "0";
	private Date startDate;
	private Date endDate;
	private String type;
	private String text;

	public Task(String type, String text) {
		this.type = type;
		this.text = text;
		this.ID = String.valueOf(IdManager.getNextId());
		BestTaskManager.setLastAssignedId(Integer.valueOf(this.ID));
	}

	public Task(String type, String text, Date startDate, Date endDate) {
		this.type = type;
		this.text = text;
		this.startDate = startDate;
		this.endDate = endDate;
		this.ID = String.valueOf(IdManager.getNextId());
		BestTaskManager.setLastAssignedId(Integer.valueOf(this.ID));
	}

	public Task(String type, String text, Date deadline) {
		this.type = type;
		this.text = text;
		this.endDate = deadline;
		this.ID = String.valueOf(IdManager.getNextId());
		BestTaskManager.setLastAssignedId(Integer.valueOf(this.ID));
	}
	
	public Task(){
		
	}
	
	public Task(Command cmd) {
		this.text = cmd.getText();
		this.startDate = cmd.getStartDate();
		this.endDate = cmd.getEndDate();		
		
		if (cmd.isFloating()) {
			this.type = "floating";
		} else if (cmd.isTimed()) {
			this.type = "timed";
		} else if (cmd.isDeadline()) {
			this.type = "deadline";
		}
		
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = startDate;
	}

	public void setText(String text) {
		this.text = text;
	}

	public void setDone(boolean done) {
		this.done = done;
	}

	public void setType(String type) {
		this.type = type;
	}

	public Date getStartDate() {
		return startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public String getText() {
		return text;
	}

	public String getType() {
		return type;
	}

	public String getID() {
		return ID;
	}

	public boolean getDone() {
		return done;
	}

	public String toString() {
		String doneStr = "0";
		
		if (done) {
			doneStr = "1";
		}
		
		String startStr = "";
		if (startDate != null) {
			startStr = startDate.toString();
		}
		
		String endStr = "";
		if (endDate != null) {
			endStr = endDate.toString();
		}
		return ID + "|" + text + "|" + startStr + "|"
				+ endStr + "|" + type + "|" + doneStr;

	}

}